// 留言墙仓库

import { getWallAPI, getMyWallAPI, findUserWallLikeAPI } from "@/api";

import store from "@/store";
const state = {
  wallCards: [],
  myWallCards: [],
  userLikeWalls: [],
};

const actions = {
  // 获取所有留言卡片
  async initWallCards({ commit }) {
    let res = await getWallAPI();
    console.log("111", res);
    if (res.status === 0) {
      commit("INITWALLCARDS", res.data);
    }
  },

  //   获取自己的留言卡片
  async initMyCards({ commit }) {
    let res = await getMyWallAPI();

    commit("INITMYCARDS", res.data);
  },

  // 获取用户点赞的留言卡片
  async getUserLikeWallID({ commit }) {
    let res = await findUserWallLikeAPI();
    if (res.status === 0) {
      commit("GETUSERLIKEWALLID", res.data);
    }
  },
};

const mutations = {
  INITWALLCARDS(state, data) {
    state.wallCards = data;
  },
  INITMYCARDS(state, data) {
    state.myWallCards = data;
  },
  GETUSERLIKEWALLID(state, data) {
    state.userLikeWalls = data;
  },
};

const getters = {
  userLikeWallIds: (state) => {
    return state.userLikeWalls.map((likeWall) => likeWall.wall_id);
  },
};

export default {
  state,
  mutations,
  actions,
  getters,
};
